﻿using System.Collections.Generic;
using System;

namespace TrainGame.Common
{
	/// <summary>
	/// A simple class to centralize tracing, especially so we can enable/disable programatically
	/// </summary>
	static public class XTrace
	{
		/// <summary>
		/// Write a trace message
		/// </summary>
		/// <param name="format"></param>
		/// <param name="args"></param>
		static public void Trace (string format, params object[] args)
		{
			if (Enabled)
				System.Diagnostics.Trace.WriteLine(string.Format(format, args));
		}

		static private bool Enabled = true;

#region push/pop methods

		/// <summary>
		/// Push the current Enabled state and set to a new enabled state
		/// </summary>
		/// <param name="newEnabledState"></param>
		static public void Push(bool newEnabledState)
		{
			stateStack.Push(Enabled);
			Enabled = newEnabledState;
		}

		/// <summary>
		/// Restore the previous Enabled state
		/// </summary>
		static public void Pop()
		{
			if (stateStack.Count > 0)
				Enabled = stateStack.Pop();
		}

		static private Stack<bool> stateStack = new Stack<bool>();

#endregion push/pop methods
	}
}
